package com.winit.cloudlink.mgmt.rabbit;

import com.winit.cloudlink.common.URL;
import com.winit.cloudlink.rabbitmq.mgmt.RabbitMgmtService;

public class RabbitMgmtServiceHelper {
    public static RabbitMgmtService getRabbitMgmtService(String url) {
        return getRabbitMgmtService(URL.valueOf(url));
    }

    public static RabbitMgmtService getRabbitMgmtService(URL url) {
        return RabbitMgmtService.builder()
                .host(url.getHost())
                .port(url.getPort() == 0 ? Constants.DEFAULT_RABBITMQ_MANAGEMENT_PORT : url.getPort())
                .credentials(url.getUsername(), url.getPassword())
                .build();
    }
}
